package spring2;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import spring2.annotation.TestObject;
import spring2.annotation.controller.UserController;
import spring2.annotation.repository.UserRepositoryImpl;
import spring2.annotation.service.UserService;
import spring2.aop1.AopOne;

/**
 *
 * @author jiangbang
 * @date 2016/11/14
 */
public class Main {

    public static void main(String[] args) {
        test2();
    }

    public static void test1(){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring2/beans-annotation.xml");
        //通过注解方式注入bean，首字母小写
        TestObject to = (TestObject) ctx.getBean("testObject");
        System.out.println(to);
        UserController userController = (UserController) ctx.getBean("userController");
        System.out.println(userController);
        //本来是UserRepositoryImpl ，但是通过value自命名啦
        UserRepositoryImpl userRepository = (UserRepositoryImpl) ctx.getBean("userRepository");
        System.out.println(userRepository);
        UserService userService = (UserService) ctx.getBean("userService");
        System.out.println(userService);
    }

    public static void test2(){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring2/beans-annotation.xml");
        AopOne aopOne = (AopOne) ctx.getBean("aopOneImpl");
        System.out.println(aopOne.add(1,2));
    }

}
